package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.enterprise.PatentEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.DialogFunction;
import com.sgb.kjwl.utils.DialogHelper;
import com.swgk.core.event.EventConstant;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class PatentAdapter extends BaseRecycleAdapter<PatentEntity> {
    Context context;
    TextView tv_tag;

    public PatentAdapter(Context context, List<PatentEntity> datas) {
        super(context, R.layout.item_patent, datas);
        this.context = context;
    }

    @Override
    public void convert(ItemViewHolder holder, PatentEntity patentEntity) {
        holder.setBinding(BR.viewModel, patentEntity);

//        ItemPatentBinding itemPatentBinding = (ItemPatentBinding) holder.getmBinding();
//        if (patentEntity.getPrice() == -1) {
//            holder.setText(R.id.price_view, "议价");
//        } else {
//            holder.setText(R.id.price_view, TextViewBindingAdapter.setMoneyForRMB(PointUtils.price(patentEntity.getPrice())));
//        }
        tv_tag = holder.getItem().findViewById(R.id.tv_item_intel_prop_publish);
        switch (patentEntity.getPublishType()) {
            case 0://个人
                tv_tag.setText("个人");
                tv_tag.setBackgroundResource(R.drawable.shape_radius_1_solid_bule);
                break;
            case 1://企业
                tv_tag.setText("企业");
                tv_tag.setBackgroundResource(R.drawable.shape_radius_1_solid_bule);
                break;
            case 2://团队
                tv_tag.setText("团队");
                tv_tag.setBackgroundResource(R.drawable.ractangle_radius_1_solid_yellow);
                break;
            default:
                tv_tag.setVisibility(View.GONE);
                break;
        }
        if (patentEntity.getLabel() != null && patentEntity.getLabel().contains("1")) {
            holder.setVisible(R.id.tv_item_intel_prop_hot, true);
        } else {
            holder.setVisible(R.id.tv_item_intel_prop_hot, false);
        }
        if (patentEntity.getLabel() != null && patentEntity.getLabel().contains("2")) {
            holder.setVisible(R.id.tv_item_intel_prop_urgent_sale, true);
        } else {
            holder.setVisible(R.id.tv_item_intel_prop_urgent_sale, false);
        }

        holder.getItem().findViewById(R.id.btn_chat).setOnClickListener((View.OnClickListener) view -> {
            if (DialogHelper.checkLogin()) {
                DialogHelper.showDialog(context, "确认呼叫", patentEntity.getContacts() + "：" + patentEntity.getContactNumber(), "确定", new DialogFunction() {
                    @Override
                    public void normalRoundDialog() {
                        ActivityJump.jumpToPhone(context, patentEntity.getContactNumber());
                    }
                });
            } else {
                DialogHelper.showLoginDialogNew(context, EventConstant.EVENT_INTELL_PROP_FRG_JUMP, "温馨提示", "登录后可拨打电话,去登录", "登录");
            }

        });

        ImageView roundImageView = holder.getItem().findViewById(R.id.logo_view);

        if (patentEntity.getImg() != null && !patentEntity.getImg().equals("")) {
            Glide.with(context).load(patentEntity.getImg()).apply(RequestOptions.bitmapTransform(new RoundedCorners(2))).into(roundImageView);
        } else {
//            roundImageView.setImageResource(R.mipmap.morentu_change);
            switch (patentEntity.getCategoryName()){
                case "发明专利":
                    Glide.with(context).load(R.mipmap.qiyefuwu_module_famingzhuanli_for_patent_publish).into(roundImageView);
                    break;
                case "实用新型":
                    Glide.with(context).load(R.mipmap.shiyongxinxing_patent_publish).into(roundImageView);
                    break;
                case "外观设计":
                    Glide.with(context).load(R.mipmap.waiguansheji_patent_publish).into(roundImageView);
                    break;
            }
        }
    }


}
